package com.smart.web.controller.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.smart.common.core.page.PageQuery;
import com.smart.system.domain.vo.CarMileageAndOilVo;
import com.smart.system.domain.vo.CarTrajectoryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smart.common.annotation.Log;
import com.smart.common.core.controller.BaseController;
import com.smart.common.core.domain.AjaxResult;
import com.smart.common.enums.BusinessType;
import com.smart.common.core.domain.R;
import com.smart.system.domain.CarTrajectory;
import com.smart.system.service.ICarTrajectoryService;
import com.smart.common.utils.poi.ExcelUtil;
import com.smart.common.core.page.TableDataInfo;

/**
 * 车辆移动轨迹Controller
 * 
 * @author smart
 * @date 2024-12-02
 */
@RestController
@RequestMapping("/system/carTrajectory")
@Api(tags = "车辆移动轨迹")
public class CarTrajectoryController extends BaseController
{
    @Autowired
    private ICarTrajectoryService carTrajectoryService;

    /**
     * 后台车辆移动轨迹
     */
    @ApiOperation(value = "后台车辆移动轨迹")
    @GetMapping("/getCarMovingTrajectory")
    public R<IPage<CarTrajectoryVo>> getCarMovingTrajectory(PageQuery query, Date startTime, Date endTime,Integer carId)
    {
        IPage<CarTrajectoryVo> list = carTrajectoryService.getCarMovingTrajectory(query,startTime,endTime,carId);
        return R.ok(list);
    }

//    /**
//     * 查询车辆移动轨迹列表
//     */
//    @ApiOperation(value = "查询车辆移动轨迹列表")
//    //@PreAuthorize("@ss.hasPermi('system:trajectory:list')")
//    @GetMapping("/list")
//    public TableDataInfo<CarTrajectory> list(CarTrajectory carTrajectory)
//    {
//        startPage();
//        List<CarTrajectory> list = carTrajectoryService.selectCarTrajectoryList(carTrajectory);
//        return getDataTable(list);
//    }

    /**
     * 获取车辆移动轨迹详细信息
     */
    @ApiOperation(value = "获取车辆移动轨迹详细信息")
    //@PreAuthorize("@ss.hasPermi('system:trajectory:query')")
    @GetMapping(value = "/{id}")
    public R<CarTrajectory> getInfo(@PathVariable("id") String id)
    {
        return R.ok(carTrajectoryService.selectCarTrajectoryById(id));
    }

    /**
     * 新增车辆移动轨迹
     */
    @ApiOperation(value = "新增车辆移动轨迹")
    //@PreAuthorize("@ss.hasPermi('system:trajectory:add')")
    @Log(title = "车辆移动轨迹", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Boolean> add(@RequestBody CarTrajectory carTrajectory)
    {
        return R.ok(carTrajectoryService.insertCarTrajectory(carTrajectory));
    }

    /**
     * 修改车辆移动轨迹
     */
    @ApiOperation(value = "修改车辆移动轨迹")
    //@PreAuthorize("@ss.hasPermi('system:trajectory:edit')")
    @Log(title = "车辆移动轨迹", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Boolean> edit(@RequestBody CarTrajectory carTrajectory)
    {
        return R.ok(carTrajectoryService.updateCarTrajectory(carTrajectory));
    }

    /**
     * 删除车辆移动轨迹
     */
    @ApiOperation(value = "删除车辆移动轨迹")
    //@PreAuthorize("@ss.hasPermi('system:trajectory:remove')")
    @Log(title = "车辆移动轨迹", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public R<Boolean> remove(@PathVariable String[] ids)
    {
        return R.ok(carTrajectoryService.deleteCarTrajectoryByIds(ids));
    }

    /**
     * 获取车辆油量与里程
     */
    @ApiOperation(value = "获取车辆油量与里程")
    @GetMapping("/getCarMileageAndOil")
    public R<CarMileageAndOilVo> getCarMileageAndOil(String carNumber,String startTime,String endTime)
    {
        CarMileageAndOilVo carTrajectory = carTrajectoryService.getCarMileageAndOil(carNumber,startTime,endTime);
        return R.ok(carTrajectory);
    }
}
